
// JavaScript Document
   var lk_OsObject = "";  //浏览器辨别
   var lk_chat_currentWin_speed;//聊天块滚动速度
   var lk_chat_bigDiv_position;//聊天大块位置
   var lk_chat_smallDiv_position;//聊天小块位置
   if(navigator.userAgent.indexOf("MSIE")>0) {  
        lk_OsObject= "MSIE";  //ie浏览器
		lk_chat_currentWin_speed=200;
   }else if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){  
        lk_OsObject= "Firefox";  //Firefox浏览器
		lk_chat_currentWin_speed=30;
   }else{  
        lk_OsObject= "Other";  //其他浏览器
		lk_chat_currentWin_speed=50;
   }
   
	var lk_chat_currentWin;//要移动的对象
	var lk_chat_top=0;//动态高度
	$.fn.lk_mywin=function(position){
	//判断用户给的对象是否为空
		if(position && position instanceof Object){
			var positionLeft=position.left;
			var positionTop=position.top;
			lk_chat_currentWin=this;	//当前要显示的对象
			var left;
			var reg=/(px)/ig;
			positionLeft=positionLeft.replace(reg,"");//将形参里的px单位去除
			positionTop=positionTop.replace(reg,"");
			if(!isNaN(positionLeft)){//将字符串转为整形
				positionLeft=parseInt(positionLeft);
			}
			if(!isNaN(positionTop)){
				positionTop=parseInt(positionTop);
			}
			var width;
			var height;
			var scrollLeft;
			var scrollTop;	
			//距左边的宽度
			function getWindow(){
				//可视区域的大小 
				width=$(window).width();
				height=$(window).height();
				scrollLeft=$(window).scrollLeft();
				scrollTop=$(window).scrollTop();
			}
			//以及要显示层的大小	
			var mywidth=lk_chat_currentWin.outerWidth(true);
			var myheight=lk_chat_currentWin.outerHeight(true);
			//获取左边的距离
			function getLeft(){
				if(positionLeft!="" && typeof(positionLeft)=="string"){
					if(positionLeft=="left"){
						left=scrollLeft;
					}else if(positionLeft=="center"){
						left=(width-mywidth)/2+scrollLeft;
					}else if(positionLeft=="right"){
						left=width-mywidth+scrollLeft;
					}else{
						left=(width-mywidth)/2+scrollLeft;
					}
				}else if(positionLeft!="" && typeof(positionLeft)=="number"){
					left=positionLeft+scrollLeft;
				}else{
					left=scrollLeft;	
				}
			}		
			//获取高度	
			function getTop(){
				if(positionTop!="" && typeof(positionTop)=="string"){
					if(positionTop=="top"){
						lk_chat_top=scrollTop;
					}else if(positionTop=="center"){
						lk_chat_top=(height-myheight)/2+scrollTop;
					}else if(positionTop=="buttom"){
						lk_chat_top=height-myheight+scrollTop;
					}else{
						lk_chat_top=(height-myheight)/2+scrollTop;
					}
				}else if(positionTop!="" && typeof(positionTop)=="number"){
					lk_chat_top=positionTop+scrollTop;
				}else{
					lk_chat_top=scrollTop;
				}
			}		
			getWindow();
			getLeft();
			getTop();
			lk_chat_currentWin.css({left:left,top:lk_chat_top});		
			$(window).unbind();
			//当滚动条运动时 视觉位置也随着改变
			$(window).bind({
				resize:function(){ 
					getWindow();
					getLeft();
					getTop();
					lk_chat_currentWin.css({left:left,top:lk_chat_top});
				},
				scroll:function(){
					getWindow();
					getLeft();
					getTop();
					if("MSIE"==lk_OsObject){
						lk_chat_currentWin.css({left:left,top:lk_chat_top});
					}else{
						lk_chat_currentWin.animate({left:left,top:lk_chat_top},lk_chat_currentWin_speed);//
						//lk_chat_currentWin.css({left:left,top:lk_chat_top});
					}
				}
			});
		}
	}
	
	$(function(){
		var currentHTML=window.location.pathname;
		//判断是否为Index页面  调整聊天块的位置
		if(currentHTML.indexOf("index.jsp")>0 || currentHTML=="/haipumi_pro/"){
			lk_chat_smallDiv_position="400px";
			lk_chat_bigDiv_position="380px";
		}else{
			lk_chat_smallDiv_position="500px";
			lk_chat_bigDiv_position="480px";
		}
		
		//初始化聊天块位置
		$("#lk_cool_effects_chatDiv").css("opacity","0.8").lk_mywin({left:"0px",top:lk_chat_smallDiv_position});//初始化透明度和小块位置
		//小块头透明度改变事件的绑定
		$("#lk_cool_effects_chatDiv").bind({
			mouseover:function(){
				$(".lk_cool_effects_chatDiv_right").css("display","block");
				$("#lk_cool_effects_chatDiv").css("opacity","1");
			},
			mouseout:function(){
				$(".lk_cool_effects_chatDiv_right").css("display","none");
				$("#lk_cool_effects_chatDiv").css("opacity","0.8");
			}
		});
		//隐藏聊天提示块事件
		/*$(".lk_cool_effects_chatDiv_right_top").bind("click",function(){
			var Chat_Confirm=confirm("您确定要隐藏消息提示窗口吗?");
			if(Chat_Confirm==true){
				$("#lk_cool_effects_chatDiv").fadeOut(1000);//.css("display","none");
			}
		});*/
		//小块进去,大块出来
		$(".lk_cool_effects_chatDiv_right_down,.lk_cool_effects_chatDiv_left").bind("click",function(){
			lk_chat_currentWin.animate({left:"-70px",top:lk_chat_top+"px"});
			$("#lk_cool_effects_chatDiv_list").css("display","none").lk_mywin({left:"0px",top:lk_chat_bigDiv_position});
			lk_chat_currentWin.css("display","block").css({left:"-800px",top:lk_chat_top+"px"});
			lk_chat_currentWin.animate({left:"0px",top:lk_chat_top+"px"},1000);
		});
		//大块进去,小块出来
		$(".lk_cool_effects_chatDiv_list_right").bind("click",function(){
			lk_chat_currentWin.animate({left:"-600px",top:lk_chat_top+"px"});
			$("#lk_cool_effects_chatDiv").css("display","none").lk_mywin({left:"0px",top:lk_chat_smallDiv_position});
			lk_chat_currentWin.css("display","block").css({left:"-70px",top:lk_chat_top+"px"});
			lk_chat_currentWin.animate({left:"0px",top:lk_chat_top+"px"},1000);
		});
		//聊天好友列表点击 以及 触碰和离开 事件
		$(".lk_cool_effects_chatDiv_contents_left_friendList li").bind({
			click:function(){
				$(".lk_cool_effects_chatDiv_contents_left_friendList li").css("background","#FFF");
				$(this).css("background","#EEE");
				var lk_friendName=$(this).children("span").text();
				$(".lk_cool_effects_chatDiv_contents_right_title span").text(lk_friendName);
				$(".lk_cool_effects_chatDiv_contents_right_message_none").css("display","none");
				
				//填写客服的id
				$("#lk_cool_effects_chatDiv_ID").attr("userid",$(this).attr("cid"))
			},
			mouseover:function(){
				$(this).css("background","#EEE");
			},
			mouseout:function(){
				if($(this).children("span").text()!=$(".lk_cool_effects_chatDiv_contents_right_title span").text()){
					$(this).css("background","#FFF");
				}
			}
		});
		//删除好友列表事件
		$(".lk_cool_effects_chatDiv_contents_left_friendList li a").bind({
			click:function(){
				$(this).parent().remove();
			}
		});
		//聊天输入框聚焦 失焦 事件
		$(".lk_cool_effects_chatDiv_list_left_input input").bind({
			blur:function(){
				$(this).css("border","1px solid #999");
			},
			focus:function(){
				$(this).css("border","1px solid #F90");
			}
		});
	});